package org.boot.wxipad.common.error;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.boot.wxipad.common.util.json.WxIpadGsonBuilder;

import java.io.Serializable;

/**
 * @author liyuncong
 * @version 1.0
 * @file WxIpadError
 * @brief WxIpad 接口调用错误
 * @details WxIpad 接口调用错误
 * @date 2024-08-05
 *
 * Edit History
 * ----------------------------------------------------------------------------
 * DATE                     NAME               DESCRIPTION
 * 2024-08-05               liyuncong          Created
 */

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Builder
public class WxIpadError implements Serializable {

    /**
     * ipad 响应时间戳
     */
    private String timestamp;

    /**
     * ipad 错误代码
     */
    private Integer status;

    /**
     * ipad 错误
     */
    private String error;

    /**
     * ipad 错误信息
     */
    private String message;

    /**
     * ipad 接口请求路径
     */
    private String path;

    /**
     * ipadBack原始响应
     */
    private String json;

    public WxIpadError(int status, String message) {
        this.status = status;
        this.message = message;
    }

    public static WxIpadError fromJson(String json) {
        return WxIpadGsonBuilder.create().fromJson(json, WxIpadError.class);
    }

    @Override
    public String toString() {
        if (this.json == null) {
            return "错误状态：" + this.status + ", 错误信息：" + this.message;
        }
        return "错误状态：" + this.status + ", 错误信息：" + this.message + ", WxIpad原始报文：" + this.json;
    }
}
